<include file="Public/head" />
<script type="text/javascript" src="/static/js/premage.js"></script>
<style type="text/css">
    .lottory_create{width:100%;}
    .lottory_create  .lc{width:100%;min-height:50px;line-height:50px;float:left;}
    .lottory_create  .lc_l{width:10%;float:left;}
    .lottory_create  .lc_r{width:80%;text-align:left;}
    .c_input{border: 1px solid #d7d7d7;height: 24px;line-height: 24px;margin: 10px 0;text-align: center;width: 320px;}
    .c_select{
        -moz-appearance: none;background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}/paimai/yunying/images/sanjiao.jpg") no-repeat scroll 300px 5px;border: 1px solid #d7d7d7;color: #666;
        float: left;font-family: "微软雅黑";height: 26px;line-height: 26px;margin: 10px 0;text-align: left;width: 320px;}
    .xiaci1{
        background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}/paimai/yunying/images/zhong_pic.jpg") no-repeat scroll 145px 4px;border: 1px solid #d7d7d7;float: left;
        height: 24px;line-height: 24px;margin: 10px 0;padding-left: 10px;text-align: left;width: 160px;}
    .genghua {background-color: #20ab4f; border: medium none;border-radius: 4px;color: #fff;cursor: pointer; display: inline-block;
              height: 30px; line-height: 30px;width: 100px;float:left;margin-left:-100px;}
    .preview-image-container{margin-left:100px;}
    .shangChuan { cursor: pointer;height: 30px; opacity: 0; width: 100px;float:left;}
</style>
</head>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="hdgl.cjgl" />
    <div class="mianR">
        <h3 class="cha">编辑活动</h3>
        <div class="lottory_create">
            <div class='lc'>
                <div class='lc_l'><b>活动名称</b></div>
                <div class='lc_r'>
                    <input type='text' name='lot_name' class='c_input' value="{$lottory.lottory_name}" placeholder='请输入活动名称'>
                    &nbsp;&nbsp;50个汉字以内
                </div>
            </div>
            <div class='lc'>
                <div class='lc_l' style="line-height:80px;"><b>活动图片</b></div>
                <div class='lc_r'>
                    <if condition="$lottory.lottory_image eq ''">
                        <img id="lottory_pic" src="">
                        <else />
                        <img id="lottory_pic" src="{$lottory.lottory_image}@80w_80h">
                    </if>
                    <script type='text/javascript'>
                        new IFrameUploadImg(
                            '浏览'
                            , 'http://' + window.location.host + '/Lottory/uploadPic'
                            , function (res) {
                                var cdn_url = '{$t|get_content_cdnurl}';

                                if (res.code == 200) {
                                    var head_url = res.data[0];
                                    var post_data = {};
                                    post_data['lottory_image'] = cdn_url + head_url;
                                    post_data['lot_id'] = "{$lottory.id}";
                                    $.ajax({
                                        type: "POST",
                                        url: "/Lottory/uploadPicInfo",
                                        data: post_data,
                                        dataType: "jsonp",
                                        success: function (data) {
                                            if (data.code == 200) {
                                                $('#lottory_pic').attr('src', cdn_url + head_url + '@80w_80h.jpg');
                                            }
                                        }
                                    });
                                }
                            });
                    </script>
                </div>
            </div>
            <div class='lc'>
                <div class='lc_l'><b>活动类型</b></div>
                <div class='lc_r'>
                    <select class="c_select" name="lot_type">
                        <option value="1">注册抽奖</option>
                    </select>
                </div>
            </div>
            <div class='lc'>
                <div class='lc_l'><b>活动奖品</b></div>
                <div class='lc_r'>
                    <input type='text' name='lot_award' class='c_input' maxlength="20" value="{$lottory.lottory_award}" placeholder='请输入奖品'>  
                    &nbsp;&nbsp;20个汉字以内
                </div>
            </div>
<!--            <div class='lc'>
                <div class='lc_l'><b>上证指数</b></div>
                <div class='lc_r'>
                    <input type='text' name='sse' class='c_input' maxlength="7" value="" placeholder='请输入上证指数'>
                </div>
            </div>
            <div class='lc'>
                <div class='lc_l'><b>深证指数</b></div>
                <div class='lc_r'>
                    <input type='text' name='szs' class='c_input' maxlength="7" value="" placeholder='请输入深证指数'>
                </div>
            </div>-->
            <div class='lc'>
                <div class='lc_l'><b>开始时间</b></div>
                <div class='lc_r'>
                    <input type='text' name='start_time' id="lottory_start_time" class='xiaci1 xin-text' value="{$lottory.lottory_start_time|date="Y-m-d H:i:s", ###}" placeholder='请选择开始时间' readonly />
                </div>
            </div>
            <div class='lc'>
                <div class='lc_l'><b>结束时间</b></div>
                <div class='lc_r'>
                    <input type='text' name='end_time' id="lottory_end_time" class='xiaci1 xin-text'  value="{$lottory.lottory_end_time|date="Y-m-d H:i:s", ###}" placeholder='请选择结束时间' readonly />
                </div>
            </div>
            <div class='lc'>
                <div class='lc_l'><b>开奖时间</b></div>
                <div class='lc_r'>
                    <input type='text' name='lot_time' id="lottory_time" class='xiaci1 xin-text' value="{$lottory.lottory_time|date="Y-m-d H:i:s", ###}" placeholder='请选择开奖时间' readonly />
                </div>
            </div>
        </div>
        <div class="yongBtn">
            <input class="queding confirm" name="submit_lottory" type="button" value="确定">
            <input class="quxiao" type="button" value="返回" onclick="history.back();">
        </div>
    </div>
    <div class="clear"></div>
</div>
<script type="text/javascript">
    $("input[name='submit_lottory']").on('click', function () {
        var lottory_name = $("input[name='lot_name']").val();
        if ($.trim(lottory_name) == '') {
            shibai_alert("抱歉，活动名称不能为空，请填写活动名称");
            return false;
        }
        if(lottory_name.length > 50){
            shibai_alert("抱歉，活动名称在50个汉字以内");
            return false;
        }
        var lottory_pic = $("#lottory_pic").attr('src');
        if (lottory_pic == '') {
            shibai_alert("抱歉，活动图片不能为空，请上传活动图片");
            return false;
        }
        var lottory_type = $("select[name='lot_type']").find("option:selected").val();
        var lottory_award = $("input[name='lot_award']").val();
        if ($.trim(lottory_award) == '') {
            shibai_alert("抱歉，活动奖品不能为空，请填写活动奖品");
            return false;
        }
        console.log(lottory_award.length);
        if(lottory_award.length > 20){
             shibai_alert("抱歉，奖品名称在20个汉字以内");
            return false;
        }
        var lottory_start_time = $("#lottory_start_time").val();
        if ($.trim(lottory_start_time) == '') {
            shibai_alert("抱歉，活动开始时间不能为空，请选择开始时间");
            return false;
        }
        var lottory_end_time = $("#lottory_end_time").val();
        if ($.trim(lottory_end_time) == '') {
            shibai_alert("抱歉，活动结束时间不能为空，请选择结束时间");
            return false;
        }
        var lottory_time = $("#lottory_time").val();
        if ($.trim(lottory_time) == '') {
            shibai_alert("抱歉，活动开奖时间不能为空，请选择开奖时间");
            return false;
        }
        var params = {
            'lot_id':{$lottory.id},
            'lottory_name': lottory_name,
//            'lottory_image': lottory_pic,
            'lottory_type': lottory_type,
            'lottory_award': lottory_award,
            'lottory_start_time': lottory_start_time,
            'lottory_end_time': lottory_end_time,
            'lottory_time': lottory_time,
        }
        $.post("/Lottory/updateLottory", params, function (data) {
            if (data.code == 200) {
                btn_alert(data.msg);
                setTimeout(function () {
                    window.location.href = "/Lottory/index";
                }, 1000);
            } else {
                shibai_alert(data.msg);
            }
        }, 'json');
    });

    $("#lottory_start_time,#lottory_end_time,#lottory_time").ymdateplugin({
        showTimePanel: true,
        changeMonth: true,
        changeYear: true,
        seconds60:true
    });
</script>
<include file="Public/foot" />
